/******************************************************************************
 * 
 * File Name	: drv_i2c.h
 *
 * Version		: V1.0
 *
 * Date		    : 
 *
 * Author		: 
 *
 * Note: this file originally from project 
 *
 *****************************************************************************/

#ifndef __DRV_I2C_H__
#define __DRV_I2C_H__

#include <stdio.h>
#include "gd32f20x.h"
#include <rtthread.h>

#define I2C_MASTER_CH		1
#define I2C_SLAVE_CH		0

//#define	IPMB_A_EN_LOW		(gpio_bit_reset(GPIOC,GPIO_PIN_8))
//#define	IPMB_A_EN_HIGH		(gpio_bit_set(GPIOC,GPIO_PIN_8))

//#define	IPMB_B_EN_LOW		(gpio_bit_reset(GPIOC,GPIO_PIN_9))
//#define	IPMB_B_EN_HIGH		(gpio_bit_set(GPIOC,GPIO_PIN_9))

typedef struct {
	volatile uint8_t 	rxbuf[128];
	volatile uint32_t 	rxcount;
	volatile uint32_t 	rxindex;
	volatile uint32_t 	rxdone;

	volatile uint8_t 	txbuf[128];
	volatile uint32_t 	txcount;
	volatile uint32_t 	txindex;
	volatile uint32_t 	txdone;

	volatile uint8_t	master;
	volatile uint8_t	send;
	volatile uint8_t	addr;
	volatile uint32_t	status;
} I2CX_INTERRUPT_DATA;

extern I2CX_INTERRUPT_DATA i2c1_data;
extern I2CX_INTERRUPT_DATA i2c0_data;

extern rt_mq_t i2c1_mq;
extern rt_mq_t i2c0_mq;

int i2c_init_data(uint32_t i2c_periph, uint8_t master, uint8_t slave_addr);
int i2c_init(uint32_t i2c_periph, uint8_t master, uint8_t slave_addr);

int i2c_reset_rx_data(uint32_t i2c_periph);
int i2c_reset_tx_data(uint32_t i2c_periph);

int i2c_master_send(uint32_t i2c_periph, uint8_t slave_addr, uint8_t *buf, uint32_t len);
int i2c_master_recv(uint32_t i2c_periph, uint8_t slave_addr, uint8_t *buf, uint32_t len);

int i2c_slave_recv(uint32_t i2c_periph, uint8_t slave_addr, uint8_t *buf, uint32_t *len);


#endif //__DRV_I2C_H__
